Imports System.IO
Imports System.Web

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents txtPathA As System.Windows.Forms.TextBox
    Friend WithEvents txtPathB As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents btnCompare As System.Windows.Forms.Button
    Friend WithEvents dgFiles As System.Windows.Forms.DataGrid
    Friend WithEvents dgFilesA_Not_B As System.Windows.Forms.DataGrid
    Friend WithEvents dgFilesB As System.Windows.Forms.DataGrid
    Friend WithEvents dgFilesB_Not_A As System.Windows.Forms.DataGrid
    Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
    Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
    Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
    Friend WithEvents TabPage3 As System.Windows.Forms.TabPage
    Friend WithEvents TabPage4 As System.Windows.Forms.TabPage
    Friend WithEvents TabPage5 As System.Windows.Forms.TabPage
    Friend WithEvents dgDiff As System.Windows.Forms.DataGrid
    Friend WithEvents txtSkipA As System.Windows.Forms.TextBox
    Friend WithEvents txtSkipB As System.Windows.Forms.TextBox
    Friend WithEvents cbxFiles As System.Windows.Forms.CheckBox
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
    Friend WithEvents btnVFSMain As System.Windows.Forms.Button
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.btnCompare = New System.Windows.Forms.Button()
        Me.txtPathA = New System.Windows.Forms.TextBox()
        Me.txtPathB = New System.Windows.Forms.TextBox()
        Me.txtSkipA = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.dgFiles = New System.Windows.Forms.DataGrid()
        Me.dgFilesA_Not_B = New System.Windows.Forms.DataGrid()
        Me.dgFilesB = New System.Windows.Forms.DataGrid()
        Me.dgFilesB_Not_A = New System.Windows.Forms.DataGrid()
        Me.dgDiff = New System.Windows.Forms.DataGrid()
        Me.TabControl1 = New System.Windows.Forms.TabControl()
        Me.TabPage1 = New System.Windows.Forms.TabPage()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.TabPage2 = New System.Windows.Forms.TabPage()
        Me.TabPage3 = New System.Windows.Forms.TabPage()
        Me.TabPage4 = New System.Windows.Forms.TabPage()
        Me.TabPage5 = New System.Windows.Forms.TabPage()
        Me.txtSkipB = New System.Windows.Forms.TextBox()
        Me.cbxFiles = New System.Windows.Forms.CheckBox()
        Me.MainMenu1 = New System.Windows.Forms.MainMenu(Me.components)
        Me.MenuItem1 = New System.Windows.Forms.MenuItem()
        Me.MenuItem3 = New System.Windows.Forms.MenuItem()
        Me.MenuItem4 = New System.Windows.Forms.MenuItem()
        Me.MenuItem2 = New System.Windows.Forms.MenuItem()
        Me.MenuItem5 = New System.Windows.Forms.MenuItem()
        Me.MenuItem6 = New System.Windows.Forms.MenuItem()
        Me.MenuItem7 = New System.Windows.Forms.MenuItem()
        Me.MenuItem8 = New System.Windows.Forms.MenuItem()
        Me.MenuItem9 = New System.Windows.Forms.MenuItem()
        Me.btnVFSMain = New System.Windows.Forms.Button()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        CType(Me.dgFiles, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.dgFilesA_Not_B, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.dgFilesB, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.dgFilesB_Not_A, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.dgDiff, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.TabControl1.SuspendLayout()
        Me.TabPage1.SuspendLayout()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.TabPage2.SuspendLayout()
        Me.TabPage3.SuspendLayout()
        Me.TabPage4.SuspendLayout()
        Me.TabPage5.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnCompare
        '
        Me.btnCompare.Location = New System.Drawing.Point(106, 120)
        Me.btnCompare.Name = "btnCompare"
        Me.btnCompare.Size = New System.Drawing.Size(90, 27)
        Me.btnCompare.TabIndex = 0
        Me.btnCompare.Text = " Compare"
        '
        'txtPathA
        '
        Me.txtPathA.Location = New System.Drawing.Point(29, 65)
        Me.txtPathA.Name = "txtPathA"
        Me.txtPathA.Size = New System.Drawing.Size(509, 22)
        Me.txtPathA.TabIndex = 1
        Me.txtPathA.Text = "Put Path here (e.g. ""C:\DocA"")"
        '
        'txtPathB
        '
        Me.txtPathB.Location = New System.Drawing.Point(29, 92)
        Me.txtPathB.Name = "txtPathB"
        Me.txtPathB.Size = New System.Drawing.Size(509, 22)
        Me.txtPathB.TabIndex = 2
        Me.txtPathB.Text = "Put Path here (e.g.""C:\DocB"")"
        '
        'txtSkipA
        '
        Me.txtSkipA.Location = New System.Drawing.Point(566, 92)
        Me.txtSkipA.Name = "txtSkipA"
        Me.txtSkipA.Size = New System.Drawing.Size(413, 22)
        Me.txtSkipA.TabIndex = 3
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.DarkBlue
        Me.Label1.Location = New System.Drawing.Point(326, 9)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(221, 27)
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "File Compare"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(595, 65)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(202, 26)
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "Skip these folder(s):"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(19, 28)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(135, 27)
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "Enter Root Folders ("
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'dgFiles
        '
        Me.dgFiles.CaptionText = "Files in A"
        Me.dgFiles.DataMember = ""
        Me.dgFiles.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgFiles.Location = New System.Drawing.Point(0, 0)
        Me.dgFiles.Name = "dgFiles"
        Me.dgFiles.PreferredColumnWidth = 275
        Me.dgFiles.RowHeaderWidth = 1
        Me.dgFiles.Size = New System.Drawing.Size(1094, 572)
        Me.dgFiles.TabIndex = 7
        '
        'dgFilesA_Not_B
        '
        Me.dgFilesA_Not_B.CaptionText = "Files in A, Not in B"
        Me.dgFilesA_Not_B.DataMember = ""
        Me.dgFilesA_Not_B.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgFilesA_Not_B.Location = New System.Drawing.Point(0, 9)
        Me.dgFilesA_Not_B.Name = "dgFilesA_Not_B"
        Me.dgFilesA_Not_B.RowHeaderWidth = 1
        Me.dgFilesA_Not_B.Size = New System.Drawing.Size(986, 388)
        Me.dgFilesA_Not_B.TabIndex = 8
        '
        'dgFilesB
        '
        Me.dgFilesB.CaptionText = "Files in B"
        Me.dgFilesB.DataMember = ""
        Me.dgFilesB.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgFilesB.Location = New System.Drawing.Point(0, 0)
        Me.dgFilesB.Name = "dgFilesB"
        Me.dgFilesB.RowHeaderWidth = 1
        Me.dgFilesB.Size = New System.Drawing.Size(986, 397)
        Me.dgFilesB.TabIndex = 9
        '
        'dgFilesB_Not_A
        '
        Me.dgFilesB_Not_A.CaptionText = "Files in B, Not in A"
        Me.dgFilesB_Not_A.DataMember = ""
        Me.dgFilesB_Not_A.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgFilesB_Not_A.Location = New System.Drawing.Point(10, 9)
        Me.dgFilesB_Not_A.Name = "dgFilesB_Not_A"
        Me.dgFilesB_Not_A.RowHeaderWidth = 1
        Me.dgFilesB_Not_A.Size = New System.Drawing.Size(986, 388)
        Me.dgFilesB_Not_A.TabIndex = 10
        '
        'dgDiff
        '
        Me.dgDiff.CaptionText = "Same file name, but different content"
        Me.dgDiff.DataMember = ""
        Me.dgDiff.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgDiff.Location = New System.Drawing.Point(19, 18)
        Me.dgDiff.Name = "dgDiff"
        Me.dgDiff.RowHeaderWidth = 1
        Me.dgDiff.Size = New System.Drawing.Size(987, 397)
        Me.dgDiff.TabIndex = 11
        '
        'TabControl1
        '
        Me.TabControl1.Controls.Add(Me.TabPage1)
        Me.TabControl1.Controls.Add(Me.TabPage2)
        Me.TabControl1.Controls.Add(Me.TabPage3)
        Me.TabControl1.Controls.Add(Me.TabPage4)
        Me.TabControl1.Controls.Add(Me.TabPage5)
        Me.TabControl1.Location = New System.Drawing.Point(19, 157)
        Me.TabControl1.Name = "TabControl1"
        Me.TabControl1.SelectedIndex = 0
        Me.TabControl1.Size = New System.Drawing.Size(2199, 646)
        Me.TabControl1.TabIndex = 12
        '
        'TabPage1
        '
        Me.TabPage1.Controls.Add(Me.dgFiles)
        Me.TabPage1.Controls.Add(Me.PictureBox1)
        Me.TabPage1.Location = New System.Drawing.Point(4, 25)
        Me.TabPage1.Name = "TabPage1"
        Me.TabPage1.Size = New System.Drawing.Size(2191, 617)
        Me.TabPage1.TabIndex = 0
        Me.TabPage1.Text = "A Files"
        '
        'PictureBox1
        '
        Me.PictureBox1.Location = New System.Drawing.Point(403, 18)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(120, 10)
        Me.PictureBox1.TabIndex = 19
        Me.PictureBox1.TabStop = False
        '
        'TabPage2
        '
        Me.TabPage2.Controls.Add(Me.dgFilesB)
        Me.TabPage2.Location = New System.Drawing.Point(4, 25)
        Me.TabPage2.Name = "TabPage2"
        Me.TabPage2.Size = New System.Drawing.Size(2191, 617)
        Me.TabPage2.TabIndex = 1
        Me.TabPage2.Text = "B Files"
        '
        'TabPage3
        '
        Me.TabPage3.Controls.Add(Me.dgFilesA_Not_B)
        Me.TabPage3.Location = New System.Drawing.Point(4, 25)
        Me.TabPage3.Name = "TabPage3"
        Me.TabPage3.Size = New System.Drawing.Size(2191, 617)
        Me.TabPage3.TabIndex = 2
        Me.TabPage3.Text = "In A, Not B"
        '
        'TabPage4
        '
        Me.TabPage4.Controls.Add(Me.dgFilesB_Not_A)
        Me.TabPage4.Location = New System.Drawing.Point(4, 25)
        Me.TabPage4.Name = "TabPage4"
        Me.TabPage4.Size = New System.Drawing.Size(2191, 617)
        Me.TabPage4.TabIndex = 3
        Me.TabPage4.Text = "In B, Not A"
        '
        'TabPage5
        '
        Me.TabPage5.Controls.Add(Me.dgDiff)
        Me.TabPage5.Location = New System.Drawing.Point(4, 25)
        Me.TabPage5.Name = "TabPage5"
        Me.TabPage5.Size = New System.Drawing.Size(2191, 617)
        Me.TabPage5.TabIndex = 4
        Me.TabPage5.Text = "Different"
        '
        'txtSkipB
        '
        Me.txtSkipB.Location = New System.Drawing.Point(566, 129)
        Me.txtSkipB.Name = "txtSkipB"
        Me.txtSkipB.Size = New System.Drawing.Size(413, 22)
        Me.txtSkipB.TabIndex = 13
        '
        'cbxFiles
        '
        Me.cbxFiles.Location = New System.Drawing.Point(154, 28)
        Me.cbxFiles.Name = "cbxFiles"
        Me.cbxFiles.Size = New System.Drawing.Size(211, 27)
        Me.cbxFiles.TabIndex = 14
        Me.cbxFiles.Text = "Files, not folders) to compare:"
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2, Me.MenuItem5})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem3, Me.MenuItem4})
        Me.MenuItem1.Text = "Help"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 0
        Me.MenuItem3.Text = "Topics"
        '
        'MenuItem4
        '
        Me.MenuItem4.Index = 1
        Me.MenuItem4.Text = "About"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 1
        Me.MenuItem2.Text = "Exit"
        '
        'MenuItem5
        '
        Me.MenuItem5.Index = 2
        Me.MenuItem5.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem6, Me.MenuItem7, Me.MenuItem8, Me.MenuItem9})
        Me.MenuItem5.Text = "File"
        '
        'MenuItem6
        '
        Me.MenuItem6.Index = 0
        Me.MenuItem6.Text = "Load A & B from Load.txt"
        '
        'MenuItem7
        '
        Me.MenuItem7.Index = 1
        Me.MenuItem7.Text = "Load A"
        '
        'MenuItem8
        '
        Me.MenuItem8.Index = 2
        Me.MenuItem8.Text = "Load B"
        '
        'MenuItem9
        '
        Me.MenuItem9.Index = 3
        Me.MenuItem9.Text = "Default file"
        '
        'btnVFSMain
        '
        Me.btnVFSMain.Location = New System.Drawing.Point(730, 9)
        Me.btnVFSMain.Name = "btnVFSMain"
        Me.btnVFSMain.Size = New System.Drawing.Size(124, 27)
        Me.btnVFSMain.TabIndex = 15
        Me.btnVFSMain.Text = "Default"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(10, 65)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(19, 18)
        Me.Label4.TabIndex = 16
        Me.Label4.Text = "A"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(10, 92)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(19, 19)
        Me.Label5.TabIndex = 17
        Me.Label5.Text = "B"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
        Me.ClientSize = New System.Drawing.Size(1028, 697)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.btnVFSMain)
        Me.Controls.Add(Me.cbxFiles)
        Me.Controls.Add(Me.txtSkipB)
        Me.Controls.Add(Me.TabControl1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.txtSkipA)
        Me.Controls.Add(Me.txtPathB)
        Me.Controls.Add(Me.txtPathA)
        Me.Controls.Add(Me.btnCompare)
        Me.Menu = Me.MainMenu1
        Me.Name = "Form1"
        Me.Text = "UM File Compare"
        CType(Me.dgFiles, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.dgFilesA_Not_B, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.dgFilesB, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.dgFilesB_Not_A, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.dgDiff, System.ComponentModel.ISupportInitialize).EndInit()
        Me.TabControl1.ResumeLayout(False)
        Me.TabPage1.ResumeLayout(False)
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.TabPage2.ResumeLayout(False)
        Me.TabPage3.ResumeLayout(False)
        Me.TabPage4.ResumeLayout(False)
        Me.TabPage5.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region


    Dim gFiles As String = "Total files: "
    Dim aFiles() As String ' first array of files to compare
    Dim bFiles() As String  'second array of files to compare
    Dim gCountFile As Integer = 0
    Dim gWidth As Int16 = 1523 ' for width of tables

#Region "Compare"
    Private Sub btnCompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompare.Click
        If System.DateTime.Now > "7/7/13" Then
            'Adjust this date as desired.
            MsgBox("Expired. Please contact representative.")
            Exit Sub
        End If
        Call CompareFilesA()
    End Sub
    Private Sub CompareFilesA()
        If txtPathA.Text.Trim.Length < 3 Then Exit Sub
        If txtPathB.Text.Trim.Length < 3 Then Exit Sub
        If cbxFiles.Checked Then
            If txtPathA.Text.Trim = txtPathB.Text.Trim Then
                MsgBox("Same file!")
                Exit Sub
            End If
            MsgBox("Files equal? " & CompareFiles(txtPathA.Text.Trim, txtPathB.Text.Trim))
            Exit Sub
        End If

        gFiles = ""
        gCountFile = 0
        ReDim Preserve aFiles(0)
        ReDim Preserve bFiles(0)
        Dim bDIr As Boolean = Directory.Exists(txtPathA.Text.Trim)
        If bDIr = False Then
            MsgBox("A is not a valid directory! (Is 'Files, not Folder' Checkbox checked?)")
            Exit Sub
        End If
        bDIr = Directory.Exists(txtPathB.Text.Trim)
        If bDIr = False Then
            MsgBox("B is not a valid directory! (Is 'Files, not Folder' Checkbox checked?)")
            Exit Sub
        End If
        Call GetSubDirectories(txtPathA.Text, 1)
        Dim strAFiles As String = "Array: "
        Dim i As Integer

        Dim iMax As Integer = UBound(aFiles) - 1
        strAFiles = "File # = " & iMax

        Dim tFileA As New DataTable
        dgFiles.PreferredColumnWidth = gWidth
        tFileA.Columns.Add("FileA")

        For i = 0 To iMax
            tFileA.Rows.Add(New String() {aFiles(i)})
        Next

        dgFiles.DataSource = tFileA
        dgFiles.CaptionText = iMax + 1 & " Files in A"
        dgFiles.ReadOnly = True

        '----------------now get next array (B files):-------------------------
        Dim tFileB As New DataTable
        dgFilesB.PreferredColumnWidth = gWidth
        tFileB.Columns.Add("FileB")
        gCountFile = 0


        Call GetSubDirectories(txtPathB.Text.Trim, 2)
        Dim strBFiles As String = "Array: "
        i = 0
        iMax = UBound(bFiles) - 1
        strBFiles = "File # = " & iMax

        For i = 0 To iMax
            tFileB.Rows.Add(New String() {bFiles(i)})
        Next
        dgFilesB.DataSource = tFileB
        dgFilesB.CaptionText = iMax + 1 & " Files in B"
        dgFilesB.ReadOnly = True

        Call CompareArrays()

    End Sub
    Sub GetSubDirectories(ByVal sDirName As String, ByVal iNum As Integer)
        Dim sDir() As String 'array of subdirectories
        Dim i As Integer
        Dim sSkipDirA As String = UCase(txtSkipA.Text.Trim)
        Dim sSkipDirB As String = UCase(txtSkipB.Text.Trim)

        Dim strDirTotal As String = "Folders: "
        If UCase(sDirName) = sSkipDirA Or UCase(sDirName) = sSkipDirB Then
            Exit Sub
        End If


        Call getFiles(sDirName, iNum)
        sDir = Directory.GetDirectories(sDirName)
        If UBound(sDir) < 0 Then

            Exit Sub
        End If
        For i = 0 To UBound(sDir)

            Call GetSubDirectories(sDir(i), iNum)
        Next

    End Sub

    Function getFiles(ByVal dirName As String, ByVal inum As Integer) As String
        '  gCountFile = 0
        Dim sFiles() As String
        Dim i As Integer
        Dim strFiles As String = "Files: "
        Dim bDIr As Boolean = Directory.Exists(dirName)

        sFiles = Directory.GetFiles(dirName)
        If UBound(sFiles) < 0 Then
            strFiles = "No files in the root of " & dirName & " folder."
        ElseIf inum = 1 Then
            Dim iFileUbound As Integer = UBound(sFiles)
            Dim iTotalUbound As Integer
            If aFiles Is Nothing Then
                iTotalUbound = 0
            Else
                iTotalUbound = UBound(aFiles)
            End If
            ReDim Preserve aFiles(iTotalUbound + iFileUbound + 1)

            strFiles = "Files in root of " & dirName & " folder: "
            For i = 0 To UBound(sFiles)
                strFiles = strFiles & vbCrLf & sFiles(i)
                aFiles(gCountFile) = sFiles(i)
                gCountFile += 1
            Next
        ElseIf inum = 2 Then
            Dim iFileUbound As Integer = UBound(sFiles)
            Dim iTotalUbound As Integer
            If bFiles Is Nothing Then
                iTotalUbound = 0
            Else
                iTotalUbound = UBound(bFiles)
            End If
            ReDim Preserve bFiles(iTotalUbound + iFileUbound + 1)

            strFiles = "Files in root of " & dirName & " folder: "
            For i = 0 To UBound(sFiles)
                strFiles = strFiles & vbCrLf & sFiles(i)
                bFiles(gCountFile) = sFiles(i)
                gCountFile += 1
            Next
        End If

        gFiles = gFiles & vbCrLf & strFiles
        Return strFiles
    End Function

    Private Function CompareFiles(ByVal file1 As String, ByVal file2 As String) As Boolean
        'Set to true if the files are equal; false otherwise
        Dim filesAreEqual As Boolean = False
        If file1 = file2 Then Return True
        Dim xx As File
        If xx.Exists(file1) = False Then
            MsgBox("Could not find File A")
            Return False
        End If
        If xx.Exists(file2) = False Then
            MsgBox("Could not find File B")
            Return False
        End If

        '------------------------------------
        Dim file1Reader As New FileStream(file1, FileMode.Open, FileAccess.Read)
        Dim file2Reader As New FileStream(file2, FileMode.Open, FileAccess.Read)
        Dim byte1 As Integer = file1Reader.ReadByte()
        Dim byte2 As Integer = file2Reader.ReadByte()

        While byte1 > -1 Or byte2 > -1
            If (byte1 <> byte2) Then
                filesAreEqual = False
                Exit While
            Else
                filesAreEqual = True
            End If
            'Read the next byte
            byte1 = file1Reader.ReadByte()
            byte2 = file2Reader.ReadByte()
        End While
        file1Reader.Close()
        file2Reader.Close()
        Return filesAreEqual
    End Function

    Sub CompareArrays()
        Dim i As Integer
        Dim j As Integer
        Dim iNum As Integer = 0
        Dim aStatus(UBound(aFiles)) As Integer '0=new, 1=no match, 2= match, 3= fc false, 4= fc true, 9= other
        Dim bStatus(UBound(bFiles)) As Integer
        Dim iTrueCount As Int32 = 0
        Dim iFalseCount As Int32 = 0
        Dim iAcount As Integer = 0
        Dim iBcount As Integer = 0
        '--first, see if all of aFiles in bFiles array
        '--sets both status arrays to 2 if there is a match
        Dim strFileA As String
        Dim strFileB As String
        Dim strFileAMod As String 'replace root folder name
        Dim strFileBMod As String 'replace root folder name
        Dim iUBAFiles As Int32 = UBound(aFiles) - 1
        Dim iUBBFiles As Int32 = UBound(bFiles) - 1

        '--set bStatus array = 7 
        For j = 0 To iUBBFiles
            bStatus(j) = 7
        Next
        For i = 0 To iUBAFiles
            strFileA = UCase(aFiles(i))
            strFileAMod = Replace(strFileA, UCase(txtPathA.Text), "Mod:")
            aStatus(i) = 1 ' No match
            For j = 0 To iUBBFiles
                strFileB = UCase(bFiles(j))
                strFileBMod = Replace(strFileB, UCase(txtPathB.Text), "Mod:")
                If strFileAMod = strFileBMod Then
                    aStatus(i) = 2 'Match
                    bStatus(j) = 2
                    If aFiles(i) Is Nothing Then Exit For
                    If bFiles(j) Is Nothing Then Exit For
                    If CompareFiles(aFiles(i), bFiles(j)) = True Then
                        aStatus(i) = 4
                        bStatus(j) = 4
                        iTrueCount += 1
                    Else
                        aStatus(i) = 3
                        bStatus(j) = 3
                        iFalseCount += 1
                    End If
                    iAcount += 1
                    Exit For
                End If
            Next
        Next

        Dim strStatusA As String = ""
        Dim strStatusB As String = ""

        '----------------
        For j = 0 To UBound(bStatus)
            strStatusB += bStatus(j).ToString & " " & bFiles(j) & vbCrLf
        Next
        '-------------
        '--Just the no-matches:
        Dim tFileNoMatch As New DataTable
        dgDiff.PreferredColumnWidth = gWidth
        tFileNoMatch.Columns.Add("FilesNotMatching")
        For j = 0 To UBound(bStatus) - 1
            If bStatus(j) = 3 Then
                tFileNoMatch.Rows.Add(New String() {bFiles(j)})
                iNum += 1
            End If
        Next

        dgDiff.DataSource = tFileNoMatch
        dgDiff.CaptionText = iNum & " Files not matching"
        dgDiff.ReadOnly = True
        strStatusB = ""
        '------------
        '--files in A, not B:

        Dim tFileAnotB As New DataTable
        Me.dgFilesA_Not_B.PreferredColumnWidth = gWidth
        iNum = 0
        tFileAnotB.Columns.Add("FilesIn_A_Not_B")
        For j = 0 To UBound(aStatus) - 1
            If aStatus(j) = 1 Then
                tFileAnotB.Rows.Add(New String() {aFiles(j)})
                iNum += 1
            End If
        Next

        Me.dgFilesA_Not_B.DataSource = tFileAnotB
        Me.dgFilesA_Not_B.CaptionText = iNum & " Files in A, not B"
        dgFilesA_Not_B.ReadOnly = True
        '----------------

        '--files in B, not A:
        iNum = 0
        Dim tFileBnotA As New DataTable
        Me.dgFilesB_Not_A.PreferredColumnWidth = gWidth
        tFileBnotA.Columns.Add("FilesIn_B_Not_A")
        For j = 0 To UBound(bStatus) - 1
            If bStatus(j) = 7 Then
                tFileBnotA.Rows.Add(New String() {bFiles(j)})
                iNum += 1
            End If
        Next

        Me.dgFilesB_Not_A.DataSource = tFileBnotA
        Me.dgFilesB_Not_A.CaptionText = iNum & " Files in B, not A"

        dgFilesB_Not_A.ReadOnly = True

        '----------------------


    End Sub



#End Region

#Region "Paths"
    Private Sub btnVFSMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVFSMain.Click
        'Prepopulate folders to compare, folders to skip:
        txtPathA.Text = "C:\temp\AA1"
        txtPathB.Text = "C:\temp\AA2"
        Me.txtSkipA.Text = "C:\temp\AA2\filtered"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Refresh()
    End Sub



    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Dim xx As File
        Dim pn As String = "PathNames.txt"
        Dim pn2 As String = "C:\temp\pathNames.txt"
        Dim pn3 As String = "D:\PathNames.txt"
        If xx.Exists(pn) = False Then
            If xx.Exists(pn2) = False Then
                If xx.Exists(pn3) = False Then
                    MsgBox("Could not find File 'PathNames.txt'")
                    Exit Sub
                Else
                    pn = pn3
                End If
            Else
                pn = pn2
            End If
        End If
        Dim FS1 As New FileStream(pn, FileMode.Open, FileAccess.Read)

        Dim SR As New StreamReader(FS1)
        Dim pathf As Array = Split(SR.ReadToEnd, vbCrLf)

        If UBound(pathf) > 0 Then
            Me.txtPathA.Text = pathf(0)
            Me.txtPathB.Text = pathf(1)
        Else
            MsgBox("Check paths in file 'PathNames.txt'. Must be two paths, one on each line.")
        End If
        SR.Close()
        FS1.Close()
    End Sub


#End Region

#Region "Menu Items"

    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        Application.Exit()
    End Sub

    Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
        'MsgBox("help is on the way....")
        Dim shell As Object
        shell = CreateObject("WScript.Shell")
        shell.Run("""C:\WINDOWS\Notepad.exe""C:\temp\pathNames.txt") 'Put a help file here
    End Sub

    Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
        MsgBox("UM, Inc. Version 1.4")
    End Sub

    Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click

        ''------------------------------------
        Dim OFD As New OpenFileDialog
        OFD.Filter = "Text Files|*.txt|All Files|*.*"
        OFD.FilterIndex = 0
        If OFD.ShowDialog = DialogResult.OK Then
            Dim FS As FileStream
            FS = OFD.OpenFile
            Dim SR As New StreamReader(FS)
            Dim pathf As Array = Split(SR.ReadToEnd, vbCrLf)

            If UBound(pathf) > 0 Then
                Me.txtPathA.Text = pathf(0)
                Me.txtPathB.Text = pathf(1)
            Else
                MsgBox("Check path names in chosen file. Must be two paths, one on each line.")
            End If
            SR.Close()
            FS.Close()
        End If
    End Sub
    Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click
        Dim OFD As New OpenFileDialog
        OFD.Filter = "Text Files|*.txt|All Files|*.*"
        OFD.FilterIndex = 0
        If OFD.ShowDialog = DialogResult.OK Then
            Me.txtPathA.Text = OFD.FileName
        End If
    End Sub

    Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
        Dim OFD As New OpenFileDialog
        OFD.Filter = "Text Files|*.txt|All Files|*.*"
        OFD.FilterIndex = 0
        If OFD.ShowDialog = DialogResult.OK Then
            Me.txtPathB.Text = OFD.FileName
        End If
    End Sub
    Private Sub MenuItem9_Click(sender As System.Object, e As System.EventArgs) Handles MenuItem9.Click
        Dim shell As Object
        shell = CreateObject("WScript.Shell")
        shell.Run("""C:\WINDOWS\Notepad.exe""C:\temp\pathNames.txt") 'default paths
    End Sub
#End Region

    Private Sub dgFiles_Navigate(sender As System.Object, ne As System.Windows.Forms.NavigateEventArgs) Handles dgFiles.Navigate

    End Sub
End Class